/*
 * Copyright (c) 2021 chwxu@outlook.com
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

<template>
  <BasicDrawer v-bind="$attrs" :isDetail="true" title="SIG申请表单（请按照模板填写）">
    <div>
      <BasicForm
        :labelWidth="100"
        :schemas="schemas"
        :actionColOptions="{ span: 24 }"
        @submit="handleSubmit"
      />
    </div>
  </BasicDrawer>
</template>
<script lang="ts">
import { defineComponent, h } from 'vue';
import { BasicDrawer } from '/@/components/Drawer';
import { BasicForm, FormSchema } from '/@/components/Form/index';
import { MarkDown } from '/@/components/Markdown';
// import { useMessage } from '/@/hooks/web/useMessage';
// import { sigApplicationAction } from '/@/api/sys/form_action';

const schemas: FormSchema[] = [
  {
    field: 'markdown',
    component: 'Input',
    label: '填表区',
    defaultValue: `# SIG-XXX
简体中文 | [English](./sig_template.md)

说明：本SIG的内容遵循OpenHarmony的PMC管理章程 [README](/zh/pmc.md)中描述的约定。

## SIG组工作目标和范围

### 工作目标
 _XXX_ 

### 工作范围
 _XXX_ 

## 代码仓
- 代码仓地址：
  - repository1名称：https://gitee.com/openharmony/xxx
  - repository2名称：https://gitee.com/openharmony-sig/xxx

## SIG组成员

### Leader
- @码云账号(https://gitee.com/xxx)

### Committers列表
- @码云账号(https://gitee.com/xxx)


### 会议
 - 会议时间：xxx
 - 会议申报：可参考[PMC例会](https://gitee.com/dongjinguang/community/blob/master/zh/pmc.md#pmc%E4%BC%9A%E8%AE%AE%E9%93%BE%E6%8E%A5)申请方式，提供石墨共享文档链接，便于SIG相关申报人自行申请议题
 - 会议链接: Welink或其他会议
 - 会议通知: 请[订阅](https://lists.openatom.io/postorius/lists/dev.openharmony.io)邮件列表 dev@openharmony.io 获取会议链接
 - 会议纪要: [归档链接地址](https://gitee.com/openharmony-sig/sig-content)

### 联系方式(可选)

- 邮件列表：dev@openharmony.io
- Zulip群组：https://zulip.openharmony.cn
- 微信群：xxx
`,
    rules: [{ required: true, trigger: 'blur' }],
    render: ({ model, field }) => {
      return h(MarkDown, {
        value: model[field],
        onChange: (value: string) => {
          model[field] = value;
        },
      });
    },
  },
];

async function handleSubmit(values: any) {
  // const { createMessage } = useMessage();
  try {
    // createMessage.success('click search,values:' + JSON.stringify(values));
    console.log(values.markdown);
    window.open(`mailto:meetings@openharmony.io?subject=[SIG申请]&body=${values.markdown}`)
    // const actionStatus = await sigApplicationAction(toRaw(values));
    // if (actionStatus) {
    //   console.log(actionStatus);
    //   if (actionStatus.result) {
    //     createMessage.success(JSON.stringify(actionStatus));
    //   } else {
    //     createMessage.error(JSON.stringify(actionStatus));
    //   }
    // } else {
    //   createMessage.error('No return value.');
    //   console.log('No return value.');
    // }
  } catch (error) {
    console.error(error);
  }
}

export default defineComponent({
  components: { BasicDrawer, BasicForm },
  setup() {
    // const { createMessage } = useMessage();
    return {
      schemas,
      handleSubmit,
    };
  },
});
</script>
